<template>
	<view class="content" :style="{paddingTop: yemiangao+'px'}">
		
		<Dzhifu
		:show="show"
		:payType="payType"
		@close="show = false"
		@uidapi="getUid_api"
		></Dzhifu>
		<view class="scroll-fix" >

			<view class="d-kuan-juzhong ">
				<!--头部-->
				<view class="d-kuan pc-dingbu">
					<DToubu 
					ref="dToubu" 
					@login-success="handleLoginSuccess"
					@clear-audio="clearAllAudio" 
					@logout-success="handleLogout"
					:dengluxianshi="denglu_xianshi"
					@update-dengluxianshi="handleUpdateDengluxianshi"
					></DToubu>
				</view>

				<!--头部-->
				<!--下面内容-->
				<view class="d-kuan d-clear">
					<uv-row customStyle="margin-bottom: 10px" :gutter="10">
						<uv-col span="2" class="pc-yincang">
							<!--左边导航-->
							<view class="d-daohang d-you-10 pc-yincang d-shang-20" id="zuo-daohang" :style="{height: leftNavHeight}">
								<!-- 左边一级导航 -->
								<view class="d-daohang-5">
									<Ddaohang  @denglu-fabu="denglu_fabu"></Ddaohang>
								</view>
							</view>
							<!--左边导航-->
						</uv-col>
						<uv-col :span="kuan_shu" id="daohangkuan">
							<view class="pc-neikuang-20">
								
								<view class="daohang-guding" id="daohanggao" 
									:style="{
									    'position': 'fixed', 
									    'top': daohang_top+'px', 
									    'z-index': 99, 
									    'background': '#f3f3f3',
									    'padding': '10rpx',
									    'width': daohangkuanzhi  // 替换未定义的rightColWidth
									}">
									<uv-tabs :list="zhishi_daohang_list" @click="yiji2" lineColor="#07bfa6" :activeStyle="{ color: '#0a9a87' }"></uv-tabs>
									<uv-tabs v-if="zhishi_daohang_list.length > 0 " :key="'erji-' + activeIndex.id"  :current="xuanzezhi" :list="erjidata" @click="erji2" lineColor="#07bfa6" :activeStyle="{ color: '#0a9a87' }"></uv-tabs>
								</view>
								<view class="d-kuan d-beijing-bai d-yuanjiao-10"  :style="{marginTop:daohanggaoHeight}">
									<view class="d-neikuang-10">
										<view class="d-biankuang-10">
											<uv-form>
												<uv-form-item class="d-zuo-10" label="赏金" prop="shangjin" borderBottom>

													<uv-input v-model="wenda_data.shangjin" border="none" placeholder="填写赏金"
														type="number" inputmode="decimal" pattern="[0-9]*" 
														@input="wenda_data.shangjin = wenda_data.shangjin.replace(/[^\d.]/g, '')"
														@click="shangjin_data"
														>
													</uv-input>
													<template v-if="uid" v-slot:right >
														<view class="d-buhuanhang">
															<text >余额：{{ uid_data.money }}</text>

															
															<uv-icon @click="show = true" name="red-packet" label="充值 " class="d-you-10"></uv-icon>
														</view>
													</template>
												</uv-form-item>
											</uv-form>
											<uv-textarea border="none" height="110" maxlength="500" customStyle="font-size: 34rpx;" v-model="wenda_data.content" count placeholder="请输入内容" @click="shangjin_data"></uv-textarea>

											
											<view class="d-kuan d-shang-10 d-clear ">
												<!--上传图片-->
												<view v-if="uid" class="d-zuo d-zuo-10 d-xia-5">
													
													<uv-upload
														:fileList="fileList1"
														name="1"
														multiple
														:leixing="1"
														:maxCount="9"
														@afterRead="afterRead"
														@delete="deletePic"
														@clickPreview="clickPreview"
														:xianshi="0"
														accept="image/*,video/*"
														:previewFullImage="true"
														width="35"
														height="35"

													></uv-upload>
												
													
													
												</view>
												
												<view class="d-you d-you-10 d-buhuanhang d-xia-5">
													<!--下拉选择 第一级-->
													<uni-data-picker
													    v-if="uid"
														placeholder="选择分类" 
														popup-title="选择子类" 
														:localdata="daohangdataTree" 
														v-model="classes"
														@change="onchange" 
														@popupclosed="popupclosed"
														clear-icon
														style="width: 150px; display: block;margin-right: 5px;height: 40px;" 
														mode="tree" 
														:showCheckbox="false">
													</uni-data-picker>
												
													
													<uv-button @click="tijiao_post"  style="height: 35px;margin-bottom: 10px;" type="info" :plain="true" text="提问"></uv-button>

												</view>


											</view>
											<view class="d-clear"></view>

										</view>
									</view>
									
								</view>
								<!--列表-->
								<view class="d-clear"></view>
								<view v-if="shenhe_shu > 0" class="d-kuan ">
									<view class="d-neikuang-10">
										<uv-button @click="shenhe" type="primary" size="small" iconColor="#ffffff" icon="chat" shape="circle" color="linear-gradient(to right, rgb(59, 216, 169), rgb(46, 127, 213))" :text="'新贴审核('+shenhe_shu+')'"></uv-button>
									</view>

								</view>
								<view class="d-clear"></view>
								<!--内容-->
									<uv-row customStyle="flex-wrap: wrap" :gutter="20" wrap>
										<uv-col v-for="(tie,index) in wenda_list" span="12" >
											<view class="d-waigao-20 d-beijing-baise d-yuanjiao-10 d-bianhua-10">
												<!--头像-->
												<view class="d-kuan ">
													<view class="d-baifen-50 d-zuo d-buhuanhang">
														<view class="d-gaokuang-40 d-kuanggao-40 d-yuanjiao-40 d-box" @click="getgeren(tie.uid)">
														    <image v-if="tie.touxiang" :src="tie.touxiang" mode="aspectFill" class="d-img-40 d-yuanjiao-50 d-beijing-hui d-img-anhei"></image>
															<image v-else src="/static/assets/images/avatar.png" mode="aspectFill" class="d-img-40 d-yuanjiao-50 d-beijing-hui d-img-anhei"></image>
														</view>
														<view class="d-kuan d-zuo-10" @click="getgeren(item.uid)">
															<view class="d-wenzi-14 d-jiacu d-wenzi-hei">{{ tie.mingcheng }} </view>
															<view class="d-wenzi-14 d-wenzi-yanse-hui d-chaochu-1">{{ tie.fabushijian }}</view>
														</view>
													</view>
													<view class="d-baifen-50 d-you">
														<view class=" d-neirong-you d-you" >
															<view class="d-biaoqian">
																<uv-tags 
																:text="tie.name" 
																size="mini"
																type="success" 
																shape="circle" 
																icon="tags-fill" 
																plain 
																plainFill
																bgColor="#ffffff"
																borderColor="#02c7b6"
																color="#02c7b6"
																iconColor="#02c7b6"
																></uv-tags>
															</view>
															<!--view v-if="denglu_xianshi == 1" @click="getGuanzhus(index,item.uid)" class="d-you d-kuan-40 d-beijing-hei d-wenzi-yanse-bai-0 d-neikuang-zuoyou-2-shangxia-4 d-wenzi-12 d-yuanjiao-50 d-neirong-juzhong" >已关注</view>
															<view v-else @click="getGuanzhus(index,item.uid)" class="d-kuan-40 d-beijing-hui-f6 d-wenzi-hei d-neikuang-zuoyou-2-shangxia-4 d-wenzi-12 d-yuanjiao-50 d-neirong-juzhong" >关 注</view-->
														</view>
													</view>

												</view>
												<view class="d-clear"></view>
												<!--内容-->
												<view class="d-zuoyou-neikuang-10 ">
													<!--标题-->
													<!--view 
														class="d-jiacu d-shang-10 d-wenzi-16 d-xia-10 d-younei-10  d-wenzi-hei d-jiacu" 
														@click="tiezi(tie.cid,tie.id)"
													>{{ tie.title }}</view-->
													<!--内容-->
													<view 
													    class="d-wenzi-17  d-shang-10 d-xia-10 d-younei-10  d-chaochu-3"
													    @click="tiezi(tie.cid,tie.id)"
													>
													<view class="d-biaoqian">
														<uv-tags 
														:text="tie.shangjin+' 元'" 
														size="mini"
														type="success" 
														shape="circle" 
														icon="red-packet" 
														plain 
														plainFill
														bgColor="#ffffff"
														borderColor="#02c7b6"
														color="#02c7b6"
														iconColor="#02c7b6"
														></uv-tags>
														</view>
														{{ tie.jianjie }}
														
													</view>
													<!--图片-->
													<view class="d-fu-kuan-10 d-buhuanhang" @click="tiezi(tie.cid,tie.id)">
														<block v-for="(itemtu, indextu) in tie.wendatu" :key="indextu">

																<view class="d-kuan-30 d-zuo d-liangbian-10" v-if="indextu < 3">
																	<image :src="itemtu" mode="aspectFill" class="d-img-100-bai d-yuanjiao-6 d-yinying-10 d-img-anhei"></image>
																</view>
															
															<!--view class="d-kuan-30 d-zuo d-liangbian-10" v-if="indextu < 9">
																<image :src="itemtu" mode="aspectFill" class="d-img-100-bai d-yuanjiao-6 d-yinying-10 d-img-anhei"></image>
															</view-->
														</block>


														<view class="d-clear"></view>
													</view>
													<view class="d-clear"></view>
													<!--评论-->
													<view class="d-kuan d-shang-10">

														<view class="">
															<uv-row customStyle="flex-wrap: wrap" :gutter="20" wrap>
																<uv-col span="3" >
																	

																</uv-col>
																<uv-col span="6"   @click="tiezi(tie.cid,tie.id)">
																	<uv-row customStyle="flex-wrap: wrap" :gutter="20" wrap>
																		<uv-col span="4">
																		    <uv-icon name="chat" color="#bbbbbb" size="18" :label="tie.pinglun" labelColor="#bbbbbb"></uv-icon>
																		</uv-col>
																		<uv-col span="4">
																			<uv-icon name="heart" color="#bbbbbb" size="18" :label="tie.shoucang" labelColor="#bbbbbb"></uv-icon>
																		</uv-col>
																		<uv-col span="4" >
																			<uv-icon name="thumb-up" color="#bbbbbb" size="18" :label="tie.dianzan" labelColor="#bbbbbb"></uv-icon>
																		</uv-col>
																	</uv-row>

																</uv-col>
																<uv-col span="3" customStyle="display: flex; justify-content: flex-end; " @click="tiezi(tie.cid,tie.id)">
																	<view class="d-kuan" style="display: flex; justify-content: flex-end; ">
																		<uv-avatar-group :urls="tie.dianzan_touxiang" size="22" gap="0.4"></uv-avatar-group>
																	</view>
																</uv-col>
															</uv-row>
														</view>
													</view>
												</view>
											</view>

										</uv-col>
										<!-- 加载状态提示 -->
										<view class="d-kuan d-juzhong d-shangxia-20" v-if="isLoading">
											<uv-loading-icon></uv-loading-icon>
  										</view>
  										<view class="d-kuan d-juzhong d-shangxia-20 d-wenzi-hui" v-if="noMoreData">
  										    <uv-divider text="没有更多数据了"></uv-divider>
											  <uv-gap height="100" bgColor="#bbb"></uv-gap>
  										</view>
									</uv-row>
							    

                                <!--列表-->

							</view>
						</uv-col>
						<uv-col span="3" class="pc-yincang">
							<view class="d-daohang d-you-10 pc-yincang d-shang-20" id="zuo-daohang" :style="{height: leftNavHeight}">
								<view class="d-you-kuang">
									<view class="d-kuan  " id="yuedu_gao" :style="{height: leftNavHeight,width: rightColWidth,marginTop: '10px'}">
										<view class=" gundong-2"  style="height: 100%; display: flex; flex-direction: column;overflow-y: auto;">
											<view class="d-yuanjiao-10  d-beijing-e3 d-bianhua-10 ">
												<view class="d-kuan ">
													<!--uv-button @click="shenqing" class="d-shang-10 d-jiacu d-wenzi-16" type="default" shape="circle"  :plain="true" text="发布小知识"></uv-button-->
													<view class="d-shang-10 d-jiacu d-wenzi-16 d-neirong-juzhong d-shangxia-10">
														<uv-row customStyle="margin-bottom: 10px">
															<uv-col span="6" class="">
																<view class="d-kuan d-neirong-juzhong">
																	<uv-count-to :fontSize="30" :start-val="0" :end-val="tongji_data" :duration="2000" :useEasing="false"></uv-count-to>
																</view>
																<view class="d-kuan d-neirong-juzhong" style="display: flex; justify-content: center; align-items: center;">
																	<uv-icon name="chat" color="#000000" size="28" label="提问"></uv-icon>
																</view>
															</uv-col>
															<uv-col span="6" >
																<view class="d-kuan d-neirong-juzhong">
																	<uv-count-to :fontSize="30" :start-val="0" :end-val="tongji_daan" :duration="2000" :useEasing="false"></uv-count-to>
																</view>
																<view class="d-kuan d-neirong-juzhong" style="display: flex; justify-content: center; align-items: center;">
																	<uv-icon name="checkbox-mark" color="#000000" size="28" label="答案"></uv-icon>
																</view>
															</uv-col>
														</uv-row>

														
													</view>
													<view class="d-clear"></view>
												<uv-cell-group>
													<uv-cell v-for="(list,index) in zhishi_shenghe_list" :key="index"  icon="more-circle" :title="list && list.title+' 知识'">

														
														<template v-slot:label>
															<text style="font-size: 28rpx;color: #999;">
																{{ list.content && list.content.inputtime }} 
															</text>
														</template>
														
														<template v-slot:value>
															<text>待审核</text>
														</template>
													</uv-cell>
													
												</uv-cell-group>
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>



						</uv-col>
					</uv-row>

				</view>
				<!--下面内容-->

			</view>
		</view>
	</view>
</template>

<script>
    import Api from '@/utils/api.js';
	import WendaApi from '@/utils/wenda_api.js';
	//var wxRequest_2 = require("../../utils/wxRequest.js");
	import { getRequest,postRequest } from '@/utils/wxRequest.js';
    //引入组件 d-toubu
    import DToubu from '@/components/d-toubu/d-toubu.vue'
	import Ddaohang from '@/components/d-daohang/d-daohang.vue'
	import Dzhifu from '@/components/d-zhifu/d-zhifu.vue'
	import UniDataPicker from '@/uni_modules/uni-data-picker/components/uni-data-picker/uni-data-picker.vue'
	
	export default {
		data() {
			return {
				id:'',
				title: 'Hello',
				leftNavHeight: '500rpx', // 默认高度
				daohangkuanzhi: '50%', // 默认值
				rightColWidth: '300px', // 默认宽度
				rightColLeft: '0px', // 添加这个属性

				daohang: [
					{
						id:'1',
						name: '首页', 
						icon: 'home',

					},
					{
						id:'2',
						name: '心理学',
						icon: 'home',
						erji: [	
							{id: '2-1', name: '情绪管理'},
					    	{id: '2-2', name: '心理疗愈'},
					    	{id: '2-3', name: '行为心理学'}
						]
					},
					
				],
				denglu_xianshi:0, // 登录显示
				erjidata:[],
				erjiindex:'',//当前激活的二级菜单索引
				activeIndex: -1, // 当前激活的一级菜单索引
				zhishi_daohang_list:[], // 知识导航列表
				wenda_list:[], // 列表
				xuanzezhi:0, // 列表
				daohanggaoHeight: '54px', // 导航栏高度

				currentPage: 1, //下拉加载
    			pageSize: 12, //下拉加载
    			isLoading: false, //下拉加载
    			noMoreData: false, //下拉加载
				kuan_shu: 7, //格大小
				kuan_quan:6,//格大小
				yemiangao:70, //顶部导航栏
				zhishi_shenghe_list:[], // 知识列表
				zhishi_shenghe_shu:0, // 知识数量
				daohang_top:0, // 导航栏高度
				shenquan_list:[], // 申请列表
				selectedValue: '', // 下拉选择的值
				daohangdataTree:[], // 选择导航
				classes: '', // 分类选择值
				wenda_data:[], //问答数据
				uid_data:[], // 用户信息
				//上传图片
				fileList1: [],//图片存储
				fabuid:{},//发布id
				uptu:[],
				tongji_data:0,
				tongji_daan:0,
				show: false,
				payType:'weixin',
				shenhe_shu:0, // 审核数量


			}
		},
		components: {
  		    DToubu,
			Ddaohang,
			UniDataPicker,
			Dzhifu

  		  },
		onReachBottom() {
  			this.onReachBottom(); //下拉加载分页
  		},
		computed: {
		  	yidenglu() {
		  	  return (this.$store.state.memberuid && this.$store.state.keycode) ? 1 : 0;
		  	},
		  	touxiang() {
		  	  return this.$store.state.member? this.$store.state.member.avatar : '';
		  	},
		  	name1() {
		  	  return this.$store.state.member? this.$store.state.member.name : '';
		  	},
			uid() {
		  	  return this.$store.state.memberuid;
		  	},
		  	keycode() {
		  	  return this.$store.state.keycode;
		  	}
		},

		mounted() {
			
			//var m = this.$store.state;
			//console.log('mmmm',m);
			
    	    this.setLeftNavHeight();
			this.getRightColWidth(); // 添加这行
			
    	    // 添加窗口大小变化监听
    	    window.addEventListener('resize', this.setLeftNavHeight);
			window.addEventListener('resize', this.getRightColWidth); // 添加窗口大小变化监听
			this.$nextTick(() => {
				// 计算高度
				//this.calcDaohanggaoHeight();
    		});

    	},
    	beforeDestroy() {
    	    // 移除监听
    	    window.removeEventListener('resize', this.setLeftNavHeight);
			window.removeEventListener('resize', this.getRightColWidth); // 添加这行
			this.clearAllAudio();
    	},
		onShow() {
			//var m = this.$store.state;
			//console.log('12300000:', this.$store.state.memberuid);
			this.wenda_daohang_api();
			var e = this;
			this.wenda_list_api(e,false);
			this.getUid_api();
			this.getFabuid_api();
			//this.shenhe_zhishi_shu();
		},
		onLoad() {
			
		},
		methods: {
			// 发布登录
			denglu_fabu(){
				if(this.yidenglu == 0){
					this.denglu_xianshi = 1;
				} else {
					this.denglu_xianshi = 0;	
				}
				
				console.log('发布登录',this.denglu_xianshi);
				
			},
			// 更新判断是否登录
			handleUpdateDengluxianshi(value) {
			  	this.denglu_xianshi = value;
			  	console.log('关闭登录',this.denglu_xianshi);
			},
			// 退出登录
			handleLogout() {
 			  // 用户退出时关闭阅读界面
 			  this.yuedu = false;

 			  // 停止并销毁音频
 			  if(this.$refs.audioPlayer) {
 			    const audioCtx = this.$refs.audioPlayer.getAudioContext();
 			    audioCtx.stop();
 			    audioCtx.destroy();
 			  }
			   //this.getDianzan_panduan_api(); // 退出登录后重新获取点赞状态
			   //this.getShoucang_panduan_api(); // 退出登录后重新获取收藏判断
 			},
			// 登录
			handleLogin() {
				//this.getDianzan_panduan_api(); // 登录后重新获取点赞状态
				//this.getShoucang_panduan_api(); //登录后重新获取收藏判断
			},

			getRightColWidth() {
				const query_2 = uni.createSelectorQuery().in(this);
				// 获取系统信息
				const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowWidth = systemInfo.windowWidth;
				var d = this;            

               this.$nextTick(() => {
					if(windowWidth >=920){
						query_2.select('#daohangkuan').boundingClientRect(data => {
    		    		    if (data) {
    		    		        this.daohangkuanzhi = `${data.width-50}px`;
    		    		    }
    		    		}).exec();

							d.gao = 20;
							d.kuan_shu = 7;
							d.kuan_quan = 6;
							d.swiperHeight = '250';
							d.daohang_top = '60';
							d.yemiangao = '70';
					} else {
						d.gao = 10;
						d.kuan_shu = 12;
						d.kuan_quan = 12;
						d.swiperHeight = '120';
						d.daohang_top = '80';
						d.yemiangao = '80';
						this.daohangkuanzhi = '100%'; // 或其他适合的默认值

					}


                 const query = uni.createSelectorQuery().in(this);
                 query.select('#youbiankuan').boundingClientRect(rect => {
                   if (rect) {
                     /*this.rightColWidth = `${rect.width+20}px`;
                     console.log('右侧列宽度:', this.rightColWidth);*/
					 	this.rightColWidth = `${rect.width-80}px`;
                    	this.rightColLeft = `${rect.left}px`; // 计算左侧位置
                    	console.log('右侧列位置:', this.rightColWidth);
                   }
                 }).exec();
               });
            },

			calcDaohanggaoHeight() {
				this.$nextTick(() => {

    		    	const query = uni.createSelectorQuery().in(this);
    		    	query.select('#daohanggao').boundingClientRect(data => {
    		    	    if (data) {
    		    	        this.daohanggaoHeight = `${data.height}px`;
							console.log('导航栏高度:', this.daohanggaoHeight);
    		    	    }
    		    	}).exec();
				});
    		},

			//首页
			shouye(){
				uni.navigateTo({
					url: '/pages/index/index',
					fail: (err) => {
						console.error('跳转失败:', err)
					}
				})
			},
			// ...其他方法保持不变...
			yiji(index) {
    		  // 切换激活的一级菜单
    		  this.activeIndex = index;
    		  // 根据激活的一级菜单显示对应的二级菜单
			  if(index == 0){
				  this.erjidata = [];
			  }else{
				  this.erjidata = this.zhishi_daohang_list[index].son;
			  }
			  const data = {
				  categories:index
			  }
			  this.wenda_list_api(data,true);
    		  //this.erjidata = this.zhishi_daohang_list[index].son;
			  console.log(this.erjidata);
    		},
			erji(index) {
    		  // 切换激活的二级菜单
    		  this.erjiindex = index;

			  const data = {
				  categories:index
			  }
			  this.wenda_list_api(data,true);
			  //console.log(index);

    		},
			yiji2(index) {
				this.xuanzezhi = 0;
				
				console.log(this.xuanzezhi);
    		  // 切换激活的一级菜单
			  setTimeout(() => {

    			  	this.activeIndex = index;
    			  	// 根据激活的一级菜单显示对应的二级菜单
				  	if(index.id == 0){
						  this.erjidata = [];
				  	}else{
						  this.erjidata = this.zhishi_daohang_list[index.index].son;
						  
				  	}
				  	const data = {
						  categories:index.id,
						  page: 1 // 重置页码
				  	}
					this.currentPage = 1; // 重置页码
					this.noMoreData = false; // 重置无更多数据标志
				  	this.wenda_list_api(data,false);
					  this.calcDaohanggaoHeight();
				}, 300);
    		  
			  
    		},
			erji2(index) {
				this.xuanzezhi = index.index;
    		  // 切换激活的二级菜单
    		  this.erjiindex = index.id;
			  this.activeIndex = index;

			  const data = {
				  categories:index.id,
				  page: 1 // 重置页码
			  }
			    this.currentPage = 1; // 重置页码
				this.noMoreData = false; // 重置无更多数据标志

			  this.wenda_list_api(data,false);
			  console.log('二级分类：',index);

    		},

			toggleErji(index) {
    		  if (this.activeIndex === index) {
    		    // 点击已激活的菜单，收起二级菜单
    		    this.activeIndex = -1;
    		    this.currentErji = [];
    		  } else {
    		    // 点击新的菜单，显示对应的二级菜单
    		    this.activeIndex = index;
    		    this.currentErji = this.zhishi_daohang_list[index].erji;
    		  }
    		},
			setLeftNavHeight() {
        	    // 获取系统信息
        	    const systemInfo = uni.getSystemInfoSync();
        	    // 计算可用高度（可根据实际需求调整计算方式）
        	    const windowHeight = systemInfo.windowHeight;
        	    const headerHeight = 70; // 头部高度估计值
        	    const calculatedHeight = windowHeight - headerHeight;
				
        	    // 设置左边导航高度
        	    this.leftNavHeight = `${calculatedHeight}px`;
        	},
			zhishi(id){
				console.log(id);
				try {
  				  uni.navigateTo({
  				    url: '/pages/ke/index?id='+id,
  				    fail: (err) => {
  				      console.error('跳转失败:', err)
  				    }
  				  })
  				} catch (e) {
  				  console.error('跳转异常:', e)
  				}
			},
			
			handleLoginSuccess() {
  			  this.$forceUpdate();
			  this.getUid_api();
  			},
			// 导航接口
			wenda_daohang_api(){
				var get_data = getRequest(WendaApi.getWenda_daohang());
				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						// 转换时间戳为日期格式
						var list = res.data && res.data.data ? res.data.data.lisi2 : [];
						var list3 = res.data.data && res.data.data.list3;

        				this.zhishi_daohang_list = list;
							this.daohangdataTree = list3;
						// 检查并处理daohangdataTree数据格式
						
					} else {
						console.error('API请求失败:', res.data.msg || '未知错误');
						// 设置默认测试数据
						
					}
				}).catch(error => {
					console.error('请求异常:', error);
					// 设置默认测试数据
					
				})
			},
			//列表接口
			wenda_list_api(data, isLoadMore = false){
				if (!data) data = {};
				if (!data) data = {};
		  		if (!data.page) data.page = 1;
		  		if (!data.categories) data.categories = 0;
		  		if (!data.search) data.search = '';
				var get_data = getRequest(WendaApi.getTiezi_list(data));
				var res;	
				get_data.then(duixin_data => {
					res = duixin_data;	
					if(res.data.code) {
						// 转换时间戳为日期格式
						var list = res.data? res.data.data.list : {};
						var tongji = res.data && res.data.data.tongji;
						var daan_tongji = res.data && res.data.data.daan_tongji;
						this.tongji_data = tongji;
						this.tongji_daan = daan_tongji;

						//
						if (isLoadMore) {
        				  // 加载更多时追加数据
        				  this.wenda_list = [...this.wenda_list, ...list];
        				} else {
        				  // 非加载更多时替换数据
        				  this.wenda_list = list;
        				}	
						// 判断是否还有更多数据
						this.noMoreData = list.length < this.pageSize;
					} else {
						uni.showToast({
							icon: 'none',
							title: '获取失败，请稍后重试'
						});
					}
					this.isLoading = false;
				}).catch(() => {
    			  this.isLoading = false;
    			  if (isLoadMore) {
    			    this.currentPage--; // 加载失败时回退页码
    			  }
    			});
			},
			// 下拉加载更多
  			onReachBottom() {
  			  if (this.isLoading || this.noMoreData) return;
  			  this.isLoading = true;
  			  this.currentPage++;
			  // 获取当前激活的分类ID
    			const currentCategoryId = this.activeIndex.id >= 0 ? this.activeIndex.id : 0;
    			
  			  const data = {
  			    page: this.currentPage,
  			    categories: currentCategoryId
  			  };
			  console.log('分页',this.activeIndex.id);
  			  this.wenda_list_api(data, true); // 添加第二个参数表示是加载更多
  			},
			// 关闭播放音频
			// 处理下拉选择变化
			handleSelectChange(e) {
				this.selectedValue = e.value;
				console.log('选择了:', e.label);
			},
			clearAllAudio() {
    		  if(this.$refs.audioPlayer) {
    		    const audioCtx = this.$refs.audioPlayer.getAudioContext();
    		    audioCtx.stop();
    		    audioCtx.destroy();
    		  }
    		},
			shenqing(){
				try {
  				  uni.navigateTo({
  				    url: '/pages/zhishi/shenqing',
  				    fail: (err) => {
  				      console.error('跳转失败:', err)
  				    }
  				  })
  				} catch (e) {
  				  console.error('跳转异常:', e)
  				}
			},
			// 申请的知识数量
			shenhe_zhishi_shu(){
				const uid = this.$store.state.memberuid;
                const keycode = this.$store.state.keycode;
				var get_data = getRequest(WendaApi.getZhishi_shu(uid,keycode));
				var res;	
				get_data.then(duixin_data => {
					res = duixin_data;	
					if(res.data.code) {
						// 转换时间戳为日期格式
						var list = res.data ? res.data.data.list : {};
						var shuliang = res.data && res.data.data.shuliang;
						this.zhishi_shenghe_shu = shuliang;	
						this.zhishi_shenghe_list = list;	
						// 判断是否还有更多数据
					}
				})
			},
			// 下拉选择变化事件
			onchange(e) {
				console.log('选择变化:', e.detail);
				
				if (e.detail && e.detail.value && e.detail.value.length > 0) {
					const selectedValues = e.detail.value;
					console.log('选中的值:', selectedValues);
					
					if (selectedValues.length >= 2 && selectedValues[1].value) {
						// 获取二级分类
						const valueStr = selectedValues[1].value.toString();
						this.classes = valueStr;
						this.id = valueStr;
					} else if (selectedValues[0].value) {
						// 获取一级分类
						this.id = selectedValues[0].value;
						this.classes = selectedValues[0].value;
					}
					console.log('最终选择的分类ID:', this.id);
				} else {
					console.log('未选择任何分类');
					this.id = '';
					this.classes = '';
				}

			},
			// 节点点击事件
			onnodeclick(e) {
				console.log('节点点击:', e);
			},
			// 弹出层打开事件 this.daohangdataTree=[];
			popupopened() {
				console.log('弹出层已打开');
			},
			// 弹出层关闭事件
			popupclosed() {
				console.log('弹出层已关闭');
				
			},
			// 获取个人信息
			getUid_api(){
				const uid = this.$store.state.memberuid;
                const keycode = this.$store.state.keycode;
				//判断  uid 和 keycode 同时存在，才执行下一步
				if(!uid || !keycode) {
					
					return;
				}

				var get_data = getRequest(Api.getUID(uid,keycode));
				var res;	
				get_data.then(duixin_data => {
					res = duixin_data;	
					if(res.data.code) {
						// 转换时间戳为日期格式
						var list = res.data ? res.data.data : {};
						
						this.uid_data = list;	
						// 判断是否还有更多数据
					}
				})

			},
			// 数据转换方法，确保符合uni-data-picker的格式要求
			transformDataForPicker(data) {
				return data.map(item => {
					// 假设原始数据中有id和name字段
					const transformedItem = {
						value: item.id || item.value,
						label: item.name || item.label
					};
						
					// 如果有子节点，递归处理
					if (item.son && Array.isArray(item.son) && item.son.length > 0) {
						transformedItem.children = this.transformDataForPicker(item.son);
					}
						
					return transformedItem;
				});
			},
			// 判断是否已经登录，没有登录就弹出登录
			shangjin_data(){
				if(!this.uid) {
					uni.showToast({
						icon: 'none',
						title: '请先登录'
					});
						
				}
				this.denglu_fabu();
			},
			tijiao_post(){
				this.denglu_fabu();
				// 提交问答
				var uid = this.$store.state.memberuid;
                var keycode = this.$store.state.keycode;

				var id = this.id;
				//
				const shuxing = '&data[shangjin]='+this.wenda_data.shangjin;


				// 上传图片
				let img = '';
				var wendatu =this.fileList1;
				wendatu.forEach(item=>{
					img+= '&data[wendatu][id][]='+item.id+'&data[wendatu][title][]=tupian'
				})
				// 内容
				var title = this.wenda_data.content;
				// 获取前30个文字
				var shortTitle = title ? title.substring(0, 20) : '';
				
				var datas = "is_ajax=1&data[title]="+shortTitle+"&data[content]="+this.wenda_data.content+"&catid="+this.id+img+shuxing;


				var post_data = postRequest(WendaApi.postWenda(uid,keycode,id),datas);
				var res;	
				post_data.then(duixin_data => {
					res = duixin_data;	
					if(res.data.code) {
						//弹出提示成功
						uni.showToast({
							icon: 'success',

							title: '提交成功'
						});
						this.wenda_data = [];
						this.fileList1 = [];
						
						this.id = '';



						
						// 判断是否还有更多数据
					} else {
						uni.showToast({
							icon: 'error',
							title: res.data.msg
						});

					}
				})

			},
			// 发布图id
			getFabuid_api(){
			var duixin = this; 
			var get_data = getRequest(WendaApi.getFabuid());
				var res;
				get_data.then(duixin_data => {
					res = duixin_data;
					if(res.data.code) {
						duixin.fabuid = res.data.data;
					} else {
						uni.showToast({
							icon: 'none',
							title: '获取失败，请稍后重试'
						});
					}
				})
		    },
			// 新增图片
			async afterRead(event) {
				var duixin = this; 
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
					console.log('event',event); 
					let lists = [].concat(event.file)
					let fileListLen = this[`fileList${event.name}`].length
					lists.map((item) => {
						// 判断文件类型
						const isImage = item.type.startsWith('image/');
						
						
						// 只处理图片和视频文件
						if (isImage ) {
							this[`fileList${event.name}`].push({
								...item,
								status: 'uploading',
								message: '上传中',
								fileType: isImage ? 'image' : 'video'
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: '不支持的文件类型，请上传图片'
							})
						}
					})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url,1)
					const id = duixin.uptu.data.id;
					console.log('uptu',duixin.uptu.data.id); 
					let item = this[`fileList${event.name}`][fileListLen]
					// 更新文件列表状态
						const updatedItem = Object.assign(item, {
							status: 'success',
							message: '',
							url: result,
							id: id,
							fileType: item.fileType // 保留文件类型信息
						})
						this[`fileList${event.name}`].splice(fileListLen, 1, updatedItem)
						fileListLen++
						
						
					}
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			//上传图片
			uploadFilePromise(url,leixing) {
				
				
				var duixin = this; 
				
				const uid = this.$store.state.memberuid;
				const keycode = this.$store.state.keycode;
				if(leixing==1){
					// 图片上传
					var upid = duixin.fabuid && duixin.fabuid.wendatu;
				}

				
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: WendaApi.postTupians(uid,keycode)+'&fid='+upid, //
						filePath: url,
						name: 'file_data',
						formData: {
							is_ajax:1
						},
						success: (res) => {
							var duixin = this; 
							if(leixing==1){
								duixin.uptu = JSON.parse(res.data);
								//打印duixin.uptu
								console.log('duixin.uptu',duixin.uptu);
								// 假设接口返回的数据中有img_url字段包含图片URL
								
								const imgUrl = duixin.uptu.data.url || '';
								console.log('服务器返回的图片URL:', imgUrl);
								setTimeout(() => {
									resolve(imgUrl)
								}, 1000)

							} else if(leixing==2){
								duixin.up_shipin = JSON.parse(res.data);
								//打印duixin.uptu
								console.log('duixin.up_shipin',duixin.up_shipin);
								const shipinUrl = duixin.up_shipin.data.url || '';
								console.log('服务器返回的图片URL:', shipinUrl);
								setTimeout(() => {
									resolve(shipinUrl)
								}, 1000)
							}

							

							
							// 注释掉自动插入逻辑，根据用户需求取消自动插入
						
							
							}
							
					});
				})
			},
			// 图片预览方法
			clickPreview(event) {
				console.log('clickPreview事件触发', event);
				// 获取当前点击的图片索引
				const index = event.index;
				// 获取所有图片的url数组
				const urls = this.fileList1.map(item => item.url);
				console.log('图片URL列表', urls);
				console.log('当前索引', index);
				// 调用uni-app的图片预览API
				uni.previewImage({
					urls: urls,
					current: index,
					success: function(res) {
						console.log('预览成功', res);
					},
					fail: function(err) {
						console.error('预览失败', err);
					}
				});
			},
			tiezi(cid,id){
				try {
  				  uni.navigateTo({
  				    url: '/pages/wenda/wenda?id='+id+'&cid='+cid,


  				    fail: (err) => {
  				      console.error('跳转失败:', err)
  				    }
  				  })
  				} catch (e) {
  				  console.error('跳转异常:', e)
  				}
			},



		}
	}
</script>

<style>

	.content {
		display: flex;
		flex-direction: column;
		/*align-items: center;*/
		/*justify-content: center;*/
		/*background-color: #f3f3f3;*/
		/*padding-top: 70px;*/
		
		overflow-x: hidden;

	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	/* 屏幕宽度大于786px时隐藏uni-page-head */
    @media (min-width: 786px) {
        uni-page-head {
            display: none !important;
            opacity: 0 !important;
            height: 0 !important;
            visibility: hidden !important;
        }
    }
	/*.d-daohang{
		
		width: 600rpx;
	}*/
	/* 添加在style部分 */
	.d-daohang-zuo {
    position: fixed;
    left: 0;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #f5f5f5;
    z-index: 100;
	box-shadow: 2px 0 5px rgba(177, 177, 177, 0.1);
  }
  
  .d-daohang-you {
    position: fixed;
    left: 180rpx;
    
    width: 180rpx;
    height: calc(100vh - 70rpx);
    background: #fff;
    z-index: 100;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  .d-erji-item {
    height: 60rpx;
    line-height: 60rpx;
    padding: 0 20rpx;
   /* border-bottom: 1px solid #f0f0f0;*/
  }
  
  .d-erji-item:active {
    background: #f5f5f5;
  }
    .you-guding-2 {
		position: fixed;

		top: 60px; /* 根据头部高度调整 */
		/*box-shadow: -2px 0 5px rgba(0,0,0,0.1);*/
		transition: all 0.3s ease;
	}
	


	
</style>
